<?php
/**
 * 移动端首页分关键字
 *
 *
 *
 *
 */

defined('InShopNC') or exit('Access Invalid!');
class wp_hotSearchControl extends SystemControl{
	public function __construct(){

		parent::__construct();
		//Language::read('mobile');
	}
	/**
	 *热门搜索列表
	 */
	public function search_listOp(){
		$model_hotsearch = Model('hotsearch');
        $hotsearch_list=$model_hotsearch->storeGetSearchList();
        Tpl::output('hotsearch_list',$hotsearch_list);
        Tpl::showpage('hotsearch.list');
	}
	
	/**
	 *编辑热门搜索
	 */
	public function search_edtOp(){
	    $model_hotsearch = Model('hotsearch');
	    $condition['search_id']=$_REQUEST['search_id'];
	    $hotsearch_info=$model_hotsearch->getSearchInfo($condition);
	    Tpl::output('hotsearch_info',$hotsearch_info);
	    Tpl::showpage('hotsearch.add');
	}
	/**
	 *新增热门搜索
	 */
	public function search_addOp(){
	    Tpl::showpage('hotsearch.add');
	}
	/**
	 *删除热门搜索
	 */
	public function search_delOp(){
	    $model_hotsearch = Model('hotsearch');
	    $where['search_id']=$_POST['search_id'];
	    $result=$model_hotsearch->delSearch($where);
	    if($result){
	        echo 1;die;
	    }else{
	        echo 0;die;
	    }
	}
	
	/**
	 * 保存
	 */
	public function search_saveOp(){
	    if($_POST['search_id'] == null || $_POST['search_id'] == 0 || empty($_POST['search_id'])){
	        $data['search_keyword']=$_POST['search_keyword'];
	        $data['sort']=$_POST['sort'];
	        $model_hotsearch = Model('hotsearch');
	        $result=$model_hotsearch->addSearch($data);
	        if($result){
	            showMessage("保存成功",'index.php?act=wp_hotSearch&op=search_list');
	        }else{
	            showDialog("新增失败，请联系开发人员");
	        }
	    }else{
	        $condition['search_id']=$_POST['search_id'];
	        $update['search_keyword']=$_POST['search_keyword'];
	        $update['sort']=$_POST['sort'];
	        $model_hotsearch = Model('hotsearch');
	        $result=$model_hotsearch->updateSearch($condition,$update);
	        if($result){
	            showMessage("保存成功",'index.php?act=wp_hotSearch&op=search_list');
	        }else{
	            showDialog("新增失败，请联系开发人员");
	        }
	    }
	    
	}

}

